package com.cyt.web.controller.reward;

import cn.hutool.core.util.StrUtil;
import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.BaseConstant;
import com.cyt.reward.model.vo.RewardStaffVo;
import com.cyt.reward.service.RewardStaffService;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.wx.model.po.WxApply;
import com.cyt.wx.service.WxApplyService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 打赏功能-员工管理控制层
 *
 * @author rong yuan
 * @date 2019-7-24 14:21:33
 */
@RestController
public class RewardStaffController extends BaseController {

    @Resource
    private RewardStaffService rewardStaffService;

    /**
     * 统一跳转
     *
     * @param pageName 页面名称
     * @param applyId 应用id
     * @return ModelAndView
     * @author shengQiang Yu
     * @date 2019-08-28 15:17:40
     */
    @RequestMapping("/reward/rewardstaff/{pageName}")
    public ModelAndView goPage(@PathVariable("pageName") String pageName, String applyId) {
        ModelAndView view = new ModelAndView("/reward/rewardstaff/"+pageName);
        view.addObject("applyId",applyId);
        return view;
    }

    /**
     * 分页查询
     *
     * @param request       请求对象
     * @param rewardStaffVo 接受参数对象
     * @param page          当前页面
     * @param limit         页面数量
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-24 14:21:33
     */
    @BaseLog(module = "打赏功能", classz = "员工管理", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/reward/rewardstaff/page", method = RequestMethod.POST)
    public ReturnResult page(HttpServletRequest request, RewardStaffVo rewardStaffVo, int page, int limit) {
        return rewardStaffService.page(rewardStaffVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-24 14:21:33
     */
    @BaseLog(module = "打赏功能", classz = "员工管理", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/reward/rewardstaff/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id,String applyId) {
        ModelAndView view = new ModelAndView("/reward/rewardstaff/rewardStaffEdit");
        if (StrUtil.isNotEmpty(id)) {
            view.addObject(rewardStaffService.selectByPrimaryKey(id));
        }
        view.addObject("applyId",applyId);
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request       请求对象
     * @param rewardStaffVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-24 14:21:33
     */
    @BaseLog(module = "打赏功能", classz = "员工管理", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/reward/rewardstaff/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, RewardStaffVo rewardStaffVo) {
        return rewardStaffService.addOrUpdate(rewardStaffVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request       请求对象
     * @param rewardStaffVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-24 14:21:33
     */
    @BaseLog(module = "打赏功能", classz = "员工管理", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/reward/rewardstaff/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, RewardStaffVo rewardStaffVo) {
        return rewardStaffService.remove(rewardStaffVo, acceptCurrentUser(request));
    }

    /**
     * 导入数据
     *
     * @param request 请求对象
     * @param file    文件对象
     * @param catalog 文件保存自定义目录
     * @param update  1、不更新已存在数据，2、更新存在数据
     * @return ReturnResult
     * @author rong yuan
     * @date 2019/7/26 15:58
     */
    @RequestMapping(value = "/reward/rewardstaff/importData", method = RequestMethod.POST)
    public ReturnResult importData(HttpServletRequest request, MultipartFile file, String catalog, String update, String applyId) {
        return rewardStaffService.importData(request, file, catalog, update, applyId, acceptCurrentUser(request));
    }
}